/*
 * @lc app=leetcode.cn id=365 lang=java
 *
 * [365] 水壶问题
 */

// @lc code=start
class Solution {
    public boolean canMeasureWater(int x, int y, int target) {
        if(target == 0) {
            return true;
        }

        if(x + y < target) {
            return false;
        }

        int big = Math.max(x, y);
        int small = x + y - big;

        if(small == 0) {
            return big == target;
        }

        while(big % small != 0) {
            int temp = small;
            small = big % temp;
            big = temp;
        }
        return target % small == 0;
    }
}
// @lc code=end

